/**
 * @param {number[]} nums
 * @param {number} k
 * @param {number} p
 * @return {number}
 */
 var countDistinct = function(nums, k, p) {
  const arr = nums.map(v => {
    if(v % p === 0) {
      return 1
    }
    return 0
  })
  const n = nums.length
  const sum = new Array(n+1).fill(0)
  for(let i = 1; i<=n; i++) {
    sum[i] = sum[i-1] + arr[i-1]
  }
  const mp = new Set()
  let ans = 0
  for(let i = 0; i<n; i++) {
    for(let j = i; j<n; j++) {
      let d = sum[j+1] - sum[i]
      if(d <= k) {
        let c = ''
        for(let x = i; x<=j; x++) {
          c += `-${nums[x]}`
        }
        if(!mp.has(c)) {
          ans++
          mp.add(c)
        }
      }
    }
  }
  return ans
};